import os, ffmpy
from tkinter import filedialog

f_names = filedialog.askopenfilenames()

def video2gif(f_name, FFmpeg = 'D:\\Program Files\\QuickCut\\ffmpeg.exe'):
    out_name = os.path.splitext(f_name)[0] + '.gif'
    ff = ffmpy.FFmpeg(
        executable=FFmpeg,
        global_options='-y -hide_banner',
        inputs={f_name:None},
        outputs={out_name:'-vf "scale=-2:240, split [a][b];[a] palettegen [p];[b][p] paletteuse"'}
    )
    print(ff.cmd)
    ff.run()

for f_name in f_names:
    video2gif(f_name)